<template>
  <div class="m_contentBox">
    <a-card :bordered="false">
      <div class="m_aCardBox">
        <!-- 查询区域 -->
        <div class="tabBox">
          <div class="table-page-search-wrapper">
            <a-form layout="inline" @keyup.enter.native="searchQuery">
              <div>
                <a-row :gutter="24">
                  <a-col :span="4">
                    <a-form-item label="">
                      <j-input placeholder="公司/机构" v-model="queryParam.name"></j-input>
                    </a-form-item>
                  </a-col>
                  <a-col :span="4">
                    <a-form-item label="">
                      <j-dict-select-tag v-model="queryParam.type" placeholder="请选择类型"
                                         dictCode="organization_type"/>
                    </a-form-item>
                  </a-col>
                  <a-col :span="8">
                    <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                    <a-button type="primary" @click="searchReset" icon="reload"
                              style="margin-left: 8px">重置
                    </a-button>
                  </a-col>
                  <a-col :span="8">
                    <div style="display: flex;justify-content: flex-end">
                      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
                    </div>
                  </a-col>
                </a-row>
              </div>
            </a-form>
          </div>
        </div>
        <!-- 查询区域-END -->
        <!-- 操作按钮区域 -->
        <!-- table区域-begin -->
        <div class="cardBox">
          <a-table ref="table" size="middle" :scroll="{ x: true }" rowKey="id" :columns="columns"
                   :dataSource="dataSource"
                   :pagination="ipagination" :loading="loading" class="j-table-force-nowrap"
                   @change="handleTableChange">
            <!-- 有权限的模块 -->
            <template slot="selectModules" slot-scope="text">
              <a-tag v-for="(item, index) in text" :key="index">{{ convert(item.moduleId) }}</a-tag>
            </template>

            <span slot="action" slot-scope="text, record">
              <a @click="handleEditOrg(record, 'module')" v-has="'platform:organization:edit'">服务管理 <a-divider
                  type="vertical"/></a>
              <a @click="handleEditOrg(record, 'info')" v-has="'platform:organization:edit'">企业信息 <a-divider
                  type="vertical"/></a>
              <a @click="handleDetail(record)">详情</a>
              <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)"
                            v-has="'platform:organization:delete'">
                <a><a-divider type="vertical"/>删除</a>
              </a-popconfirm>
            </span>
          </a-table>
        </div>
      </div>
    </a-card>

    <cy-platform-organization-info-modal ref="modalForm" @ok="modalFormOk"></cy-platform-organization-info-modal>
  </div>
</template>

<script>

import '@/assets/less/TableExpand.less'
import {mixinDevice} from '@/utils/mixin'
import {getAction} from '@/api/manage'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import CyPlatformOrganizationInfoModal from './modules/CyPlatformOrganizationInfoModal.Style#Drawer'
import {filterDictTextByCache} from '@/components/dict/JDictSelectUtil'

export default {
  name: 'CyPlatformOrganizationInfoList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    CyPlatformOrganizationInfoModal
  },
  data() {
    return {
      description: '平台组织管理管理页面',
      modules: [],
      // 表头
      columns: [
        {
          title: '公司/机构',
          align: "center",
          dataIndex: 'name'
        },
        {
          title: '组织类型',
          align: "center",
          dataIndex: 'type_dictText'
        },
        {
          title: '状态',
          align: "center",
          dataIndex: 'state',
          customRender: (text, record, index) => {
            return filterDictTextByCache("organization_state", text)
          }
        },
        {
          title: '联系人',
          align: "center",
          dataIndex: 'contactUser'
        },
        {
          title: '联系电话',
          align: "center",
          dataIndex: 'contactNumber',
          customRender: (text, record, index) => {
            if (!text) {
              return '-'
            }
            return record.contactNumberPrefix + ':' + text;
          }
        },
        {
          title: '联系邮箱',
          align: "center",
          dataIndex: 'contactMail'
        },
        {
          title: '认证用户',
          align: "center",
          dataIndex: 'approveUser_dictText'
        },
        {
          title: '认证时间',
          align: "center",
          dataIndex: 'approveDate'
        },
        {
          title: '开通服务数量',
          align: "center",
          key: 'selectModulesSize',
          customRender: (record) => {
            return record.selectModules ? record.selectModules.length : '0'
          }
        },
        {
          title: '开通功能',
          align: "center",
          dataIndex: 'selectModules',
          scopedSlots: {customRender: 'selectModules'}
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          fixed: "right",
          width: 147,
          scopedSlots: {customRender: 'action'}
        }
      ],
      url: {
        list: "/platform/cyPlatformOrganizationInfo/list",
        delete: "/platform/cyPlatformOrganizationInfo/delete",
        deleteBatch: "/platform/cyPlatformOrganizationInfo/deleteBatch",
        exportXlsUrl: "/platform/cyPlatformOrganizationInfo/exportXls",
        importExcelUrl: "platform/cyPlatformOrganizationInfo/importExcel",
        listModules: "/platform/cyPlatformOrganizationPermission/listModules",

      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.listModules()
  },
  computed: {},
  methods: {
    listModules() {
      getAction(this.url.listModules).then((res) => {
        this.modules = res;
      })
    },
    convert(moduleId) {

      const module = _.find(this.modules, ['id', moduleId])
      return module ? module.name : ''
    },
    handleEditOrg(record, type) {
      const newRecord = {...record, type: type}
      this.handleEdit(newRecord)
    }
  }
}
</script>
<style scoped>

/deep/ .ant-card-body {
  background: #F5F8F7;
}

.tabBox {
  padding: 24px 24px 0;
  background: #FFFFFF;
  border-radius: 3px;
}

.cardBox {
  margin-top: 24px;
  padding: 24px;
  background: #FFFFFF;
  border-radius: 3px;
}
</style>